import java.io.File;
import java.io.IOException;

import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLException;
import javax.media.opengl.glu.GLU;
import javax.swing.JFrame;

import com.sun.opengl.util.Animator;
import com.sun.opengl.util.GLUT;
import com.sun.opengl.util.texture.Texture;
import com.sun.opengl.util.texture.TextureIO;



public class gl extends JFrame {
	Animator anim;

	Texture testbg;

	public gl() {

		GLCapabilities glCaps = new GLCapabilities();
		
		
		
		GLCanvas glCanvas = new GLCanvas(glCaps);
		glCanvas.addGLEventListener(new GLFrameDrawer());
		this.add(glCanvas);		



		anim = new Animator();
		anim.add(glCanvas);
		anim.start();
		
		
		this.setTitle("GarbooGL alpha");

		this.setSize(600, 400);
		this.setVisible(true);
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
	}

	public class GLFrameDrawer implements GLEventListener{

		public void display(GLAutoDrawable drawable) {
        	GL gl = drawable.getGL();

            gl.glDisable(GL.GL_DEPTH_TEST);
            
            gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);  
            gl.glClear(GL.GL_COLOR_BUFFER_BIT);
            
            gl.glBlendFunc (GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
            gl.glEnable (GL.GL_BLEND);


            
            /****/
        	
        	gl.glMatrixMode(GL.GL_PROJECTION);
          
        	gl.glLoadIdentity();
            gl.glOrtho(0, 400, 400, 0, 0, 1);
          
            
            /****/
            gl.glMatrixMode(GL.GL_MODELVIEW);
          
        	
        	testbg.enable();
        	testbg.bind();
        	gl.glBegin(GL.GL_QUADS);
        	gl.glTexCoord2d(0,0);
        	gl.glVertex2d(0,0);
        	
           	gl.glTexCoord2d(1,0);
        	gl.glVertex2d(200,0);
        	
           	gl.glTexCoord2d(1,1);
        	gl.glVertex2d(200,200);
        	
           	gl.glTexCoord2d(0,1);
        	gl.glVertex2d(0,200);
        	gl.glEnd();
        	
		}


		public void init(GLAutoDrawable drawable) {
			try {
				testbg = TextureIO.newTexture(new File("Levels/11_bg.png"), false);
			} catch (Exception e) {
				System.out.println("err");
				e.printStackTrace();
				System.exit(0);		
			}

			testbg.enable();

		}

		public void displayChanged(GLAutoDrawable drawable, boolean arg1,boolean arg2) {}
		public void reshape(GLAutoDrawable drawable, int arg1, int arg2, int arg3,int arg4) {}

	}

	public static void main(String[]args){ 
		System.out.println("lulz, gl");
		new gl(); 
	}

}

//import javax.media.opengl.GL;
//import javax.media.opengl.GLAutoDrawable;
//import javax.media.opengl.GLCanvas;
//import javax.media.opengl.GLEventListener;
//import javax.swing.JFrame;
// 
// 
//public class gl {
// 
//    public gl() {
//    	JFrame frame = new JFrame("Draw First 2D Graphics");
//        frame.setSize(400,400);
//        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//        GLCanvas canvas = new GLCanvas();
//        canvas.addGLEventListener(new JOGLListener());
//        frame.add(canvas);
//        frame.setVisible(true);
// 
//    }
// 
//    public static void main(String args[]){
//         new gl();
//    }
// 
// 
//    private class JOGLListener implements GLEventListener {
// 
//            @Override
//            public void display(GLAutoDrawable drawable) {
//                System.out.println("DISPLAY CALLED");
//            	GL gl = drawable.getGL();
//              //Projection mode is for setting camera
//            	gl.glMatrixMode(GL.GL_PROJECTION);
//              //This will set the camera for orthographic projection and allow 2D view
//              //Our projection will be on 400 X 400 screen
//                gl.glLoadIdentity();
//                gl.glOrtho(0, 400, 400, 0, 0, 1);
//              //Modelview is for drawing
//                gl.glMatrixMode(GL.GL_MODELVIEW);
//              //Depth is disabled because we are drawing in 2D
//                gl.glDisable(GL.GL_DEPTH_TEST);
//              //Setting the clear color (in this case black)
//              //and clearing the buffer with this set clear color
//                gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);  
//                gl.glClear(GL.GL_COLOR_BUFFER_BIT);
//              //This defines how to blend when a transparent graphics
//              //is placed over another (here we have blended colors of
//              //two consecutively overlapping graphic objects)
//                gl.glBlendFunc (GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
//                gl.glEnable (GL.GL_BLEND);
//              //After this we start the drawing of object  
//              //We want to draw a triangle which is a type of polygon
//                gl.glBegin(GL.GL_POLYGON);
//              //We want to draw triangle in red color
//              //So setting the gl color to red
//                gl.glColor4f(1, 0, 0, 1);
//              //Making vertices of the triangle  
//                gl.glVertex2d(100, 100);
//            	gl.glVertex2d(100, 200);
//            	gl.glVertex2d(200, 200);
//              //Our polygon ends here	
//            	gl.glEnd();
//                gl.glFlush();
//            }
// 
//            @Override
//            public void displayChanged(GLAutoDrawable arg0, boolean arg1,
//                            boolean arg2) {
//                    System.out.println("DISPLAY CHANGED CALLED");
//            }
// 
//            @Override
//            public void init(GLAutoDrawable drawable) {
//                    System.out.println("INIT CALLED");
//            }
// 
//            @Override
//            public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3,
//                            int arg4) {
//                    System.out.println("RESHAPE CALLED");
// 
//            }     
//    }
//}